// Animations
$switch_animation: switch_ripple_effect 0.3s cubic-bezier(0, 0, 0.2, 1);

@keyframes switch_ripple_effect {
  from {
    background-image: radial-gradient(circle farthest-corner at center,
                                      $selected_bg_color 0%,
                                      transparent 0%);
  }

  to {
    background-image: radial-gradient(circle farthest-corner at center,
                                      $selected_bg_color 100%,
                                      transparent 0%);
  }
}

@keyframes header_ripple_effect {
  from {
    background-image: radial-gradient(circle farthest-corner at center,
                                      $header_bg 0%,
                                      transparent 0%);
  }

  to {
    background-image: radial-gradient(circle farthest-corner at center,
                                      $header_bg 100%,
                                      transparent 0%);
  }
}

// Drawing mixins

// Solid color image
@function _solid($c) {
  @return linear-gradient(to bottom, $c, $c);
}

// Entries

@mixin entry($t) {
//
// Entries drawing function
//
// $t: entry type
//

  @if $t==normal {
  //
  // normal entry
  //
    color: $text_color;
    background-color: $entry_bg;
    outline: none;
  }

  @if $t==focus {
  //
  // focused entry
  //
    color: $text_color;
    background-color: $entry_bg;
    outline: none;
  }

  @if $t==insensitive {
  //
  // insensitive entry
  //
    color: $disabled_fg_color;
    background-color: rgba($entry_bg, 0.55);
  }

  @if $t==header-normal {
  //
  // normal header-bar entry
  //
    color: $header_fg;
    background-color: rgba($header_fg, 0.06);
    background-image: $header_button_image;
    outline: none;

    @if $variant == 'dark' {
      box-shadow: inset 0 1px $header_button_highlight;
    }

    image, image:hover { color: inherit; }
  }

  @if $t==header-focus {
  //
  // focused header-bar entry
  //
    background-image: none;
    background-color: $header_button_bg;
    outline: none;

    @if $variant == 'dark' {
      box-shadow: inset 0 1px transparent;
    }
  }

  @if $t==header-insensitive {
  //
  // insensitive header-bar entry
  //
    color: rgba($header_fg, 0.35);
    background-color: $header_button_bg;
    opacity: 1;

    @if $variant == 'dark' {
      box-shadow: inset 0 1px $header_button_highlight;
    }
  }

  @else if $t==osd {
  //
  // normal osd entry
  //
    color: $osd_fg_color;
    border-color: $osd_entry_border;
    background-color: $osd_entry_bg;

    image, image:hover { color: inherit; }
  }

  @else if $t==osd-focus {
  //
  // active osd entry
  //
    color: $selected_fg_color;
    border-color: darken($selection_mode_bg, 5%);
    background-color: $selected_bg_color;
  }

  @else if $t==osd-insensitive {
  //
  // insensitive osd entry
  //
    color: $osd_fg_color;
    background-color: transparentize($osd_entry_bg, 0.15);
    opacity: 1;
  }
}

// Buttons

@mixin button($t, $actionb_bg:red, $actionb_fg: green) {
//
// Button drawing function
//
// $t:    button type,
// $actionb_bg, $actionb_fg: used for destructive and suggested action buttons

  @if $t==normal {
  //
  // normal button
  //
    color: $fg_color;
    border-color: $button_borders;
    border-top-color: $button_borders_top;
    border-bottom-color: $button_borders_bottom;
    background-color: $button_bg;
    background-clip: padding-box;
    background-origin: padding-box;

    @if $variant=='light' { box-shadow: $shadow_3; }
    @if $variant=='dark' {
      box-shadow: inset 0 1px $button_highlight, $shadow_3;
    }
  }

  @else if $t==hover {
  //
  // hovered button
  //
    color: if($variant == 'light', darken($fg_color, 10%), lighten($fg_color, 10%));
    border-color: $button_borders_hover;
    border-top-color: $button_borders_hover_top;
    border-bottom-color: $button_borders_hover_bottom;
    background-color: if($variant=='light', darken($button_bg, 3%), lighten($button_bg, 3%));
    background-clip: padding-box;
    background-origin: padding-box;

    @if $variant=='light' { box-shadow: none; }
    @if $variant=='dark' {
      box-shadow: inset 0 1px rgba($button_highlight, 0.12), $shadow_3;
    }
  }

  @else if $t==active {
  //
  // pushed button
  //
    color: $selected_fg_color;
    background-color: $selected_bg_color;
    border-color: $button_borders_active;
    border-top-color: $button_borders_active_top;
    border-bottom-color: $button_borders_active_bottom;
    background-image: $button_active_image;

    @if $variant=='light' { box-shadow: none; }
  }

  @else if $t==insensitive {
  //
  // insensitive button
  //
    label, & {
      color: $disabled_fg_color;
      opacity: 1;
    }

    border-color: if($variant == 'light', $button_border, $dark_borders_color);
    background-color: rgba($button_bg, 0.55);
    background-image: none;

    @if $variant=='light' { box-shadow: $shadow_3; }
  }

  @else if $t==insensitive-active {
  //
  // insensitive pushed button
  //
    label, & { color: transparentize($selected_fg_color, 0.45); }

    border-color: if($variant == 'light', transparentize($selected_bg_color, 0.25), $dark_borders_color);
    background-color: rgba($selected_bg_color, 0.55);
    background-image: none;
    @if $variant=='light' { box-shadow: none; }
  }

  @if $t==flat-normal {
  //
  // normal button
  //
    border: none;
    background-color: transparent;
    background-image: none;
    box-shadow: none;
    background-clip: if($variant=='light', border-box, padding-box);
  }

  @else if $t==flat-hover {
  //
  // hovered button
  //
    color: darken($fg_color, 10%);
    background-color: if($variant=='light', rgba(black, 0.15), rgba(white, 0.15));
    background-image: none;
    box-shadow: none;
  }

  @else if $t==flat-active {
  //
  // pushed button
  //
    background-image: none;
    color: $selected_fg_color;
    background-color: if($variant=='light', rgba(black, 0.5), rgba(white, 0.25));
    box-shadow: none;
  }

  @else if $t==flat-checked {
  //
  // pushed button
  //
    background-image: none;
    color: $selected_fg_color;
    background-color: if($variant=='light', rgba(black, 0.65), rgba(white, 0.35));
    box-shadow: none;
  }

  @else if $t==flat-insensitive {
  //
  // insensitive button
  //
    label, & {
      color: $disabled_fg_color;
      opacity: 1;
    }

    background-color: transparent;
    box-shadow: none;
  }

  @else if $t==flat-insensitive-active {
  //
  // insensitive pushed button
  //
    label, & { color: transparentize($selected_fg_color, 0.2); }

    background-color: lighten($fg_color, 20%);
    opacity: 0.6;
  }

  @if $t==header-normal {
  //
  // normal header-bar button
  //
    border-color: $borders_color;
    color: $header_fg;
    background-color: $header_button_bg;
    background-image: $header_button_image;

    @if $variant == 'dark' {
      border: none;
      box-shadow: inset 0 1px $header_button_highlight;
    }
  }

  @else if $t==header-hover {
  //
  // hovered header-bar button
  //
    border-color: $borders_color;
    color: darken($header_fg, 2%);
    background-color: $header_button_hover_bg;
    background-image: $header_button_hover_image;

    @if $variant == 'dark' { box-shadow: inset 0 1px $header_button_hover_highlight; }
  }

  @else if $t==header-active {
  //
  // pushed header-bar button
  //
    color: $selected_fg_color;
    background-color: $header_button_active_bg;
    background-image: none;
    border-color: mix($fg_color, $header_button_active_bg, 15%);
  }

  @else if $t==header-checked {
  //
  // pushed header-bar button
  //
    color: if($variant=='light', $selected_fg_color, $bg_color);
    background-color: $header_button_checked_bg;
    background-image: $header_button_checked_image;
    border-color: $borders_color;

    @if $variant == 'dark' { box-shadow: inset 0 1px $header_button_checked_highlight; }
  }

  @else if $t==header-insensitive {
  //
  // insensitive header-bar button
  //
    label, & {
      color: rgba($header_fg, 0.35);
      opacity: 1;
    }

    background-color: rgba($header_button_bg, 0.45);
    box-shadow: none;
  }

  @else if $t==header-insensitive-checked {
  //
  // header-bar insensitive pushed button
  //
    label, & { color: if($variant=='light', rgba($selected_fg_color, 0.45), rgba($bg_color, 0.45)); }
    background-color: rgba($header_button_active_bg, 0.55);
    box-shadow: none;
  }

  @else if $t==osd {
  //
  // normal osd button
  //
    color: $osd_fg_color;
    border-color: $osd_button_border;
    background-color: $osd_button_bg;
    box-shadow: none;
  }

  @else if $t==osd-hover {
  //
  // active osd button
  //
    color: $osd_fg_color;
    border-color: $osd_button_border;
    background-color: opacify(lighten($osd_button_bg, 7%), 0.1);
    box-shadow: none;
  }

  @else if $t==osd-active {
  //
  // active osd button
  //
    color: $selected_fg_color;
    border-color: if($variant == 'light', $selected_bg_color, $osd_button_border);
    background-color: $selected_bg_color;
    background-image: none;
    box-shadow: none;
  }

  @else if $t==osd-insensitive {
  //
  // insensitive osd button
  //
    color: $osd_disabled_fg_color;
    border-color: $osd_button_border;
    background-color: transparentize($osd_button_bg, 0.15);
    box-shadow: none;
    opacity: 1;
  }

  @else if $t==suggested_destructive {
  //
  // suggested or destructive action buttons
  //
    @if $variant == 'light' { background-clip: border-box; }

    color: $actionb_fg;
    background-color: $actionb_bg;
    border-color: if($variant == 'light', darken($actionb_bg, 6%), $dark_borders_color);
    background-image: none;
    box-shadow: if($variant=='light', none, (inset 0 1px rgba(white, 0.15), inset 0 -1px rgba(white, 0.03)));
  }

  @else if $t==undecorated {
  //
  // reset
  //
    border-color: transparent;
    background-color: transparent;
    background-image: none;
    box-shadow: none;
  }
}

//
// Overshoot
//
@mixin overshoot($p, $t:normal, $c:$fg_color) {
//
// overshoot
//
// $p: position
// $t: type
// $c: base color
//
// possible $p values:
// top, bottom, right, left
//
// possible $t values:
// normal, backdrop
//

  $_small_gradient_length: 5%;
  $_big_gradient_length: 100%;

  $_position: center top;
  $_small_gradient_size: 100% $_small_gradient_length;
  $_big_gradient_size: 100% $_big_gradient_length;

  @if $p==bottom {
    $_position: center bottom;
    $_linear_gradient_direction: to top;
  }

  @else if $p==right {
    $_position: right center;
    $_small_gradient_size: $_small_gradient_length 100%;
    $_big_gradient_size: $_big_gradient_length 100%;
  }

  @else if $p==left {
    $_position: left center;
    $_small_gradient_size: $_small_gradient_length 100%;
    $_big_gradient_size: $_big_gradient_length 100%;
  }

  $_small_gradient_color: $c;
  $_big_gradient_color: $c;

  @if $c==$fg_color {
    $_small_gradient_color: $borders_color;
    $_big_gradient_color: $text_color;

    @if $t==backdrop { $_small_gradient_color: $fill_color; }
  }

  $_small_gradient: -gtk-gradient(radial,
                                  $_position, 0,
                                  $_position, 0.5,
                                  to($_small_gradient_color),
                                  to(rgba($_small_gradient_color, 0)));

  $_big_gradient: -gtk-gradient(radial,
                                $_position, 0,
                                $_position, 0.6,
                                from(rgba($_big_gradient_color, 0.07)),
                                to(rgba($_big_gradient_color, 0)));

  @if $t==normal {
    background-image: $_small_gradient, $_big_gradient;
    background-size: $_small_gradient_size, $_big_gradient_size;
  }

  @else if $t==backdrop {
    background-image: $_small_gradient;
    background-size: $_small_gradient_size;
  }

  background-repeat: no-repeat;
  background-position: $_position;

  background-color: transparent; // reset some properties to be sure to not inherit them somehow
  border: none;                  //
  box-shadow: none;              //
}

@mixin overshoot_alt($p) {
//
// overshoot
//
// $p: position
//
// possible $p values:
// top, bottom, right, left
//

  $_small_gradient_length: 3%;
  $_big_gradient_length: 50%;

  $_small_gradient_size: 100% $_small_gradient_length;
  $_big_gradient_size: 100% $_big_gradient_length;

  @if $p==right or $p==left {
    $_small_gradient_size: $_small_gradient_length 100%;
    $_big_gradient_size: $_big_gradient_length 100%;
  }

  $_small_gradient: radial-gradient(farthest-side at $p,
                                    gtkalpha(currentColor, 0.12) 85%,
                                    gtkalpha(currentColor, 0));

  $_big_gradient: radial-gradient(farthest-side at $p,
                                  gtkalpha(currentColor, 0.05),
                                  gtkalpha(currentColor, 0));

  background-image: $_small_gradient, $_big_gradient;
  background-size: $_small_gradient_size, $_big_gradient_size;

  background-repeat: no-repeat;
  background-position: $p;

  background-color: transparent; // reset some properties to be sure to not inherit them somehow
  border: none;                  //
  box-shadow: none;              //
}

@mixin undershoot($p, $c: $overlay_color, $neighbor: false, $style: default) {
//
// undershoot
//
// $p: position
// $c: shade color
// $neighbor: use ~ instead of >
//
// possible $p values:
// top, bottom, right, left
//

  $_border_pos: '';
  $_direction: '';
  $_selector: if($neighbor, '~', '>');

  @if $p==top {
    $_direction: bottom;
    $_border_pos: 0 1px;
  } @else if $p==bottom {
    $_direction: top;
    $_border_pos: 0 -1px;
  } @else if $p==left {
    $_direction: right;
    $_border_pos: 1px 0;
  } @else if $p==right {
    $_direction: left;
    $_border_pos: -1px 0;
  } @else {
    @error "Unknown position #{$p}"
  }

  #{$_selector} undershoot.#{$p} {
    box-shadow: if($style == 'default', none, inset $_border_pos $borders_color);
    background: linear-gradient(to $_direction, gtkalpha($c, .75), transparent 8px);
  }
}

@mixin background-shadow($direction, $color) {
  background-image:
  linear-gradient($direction,
                  gtkalpha($color, 0.7),
                  gtkalpha($color, 0.14) 40px,
                  gtkalpha($color, 0) 56px),
  linear-gradient($direction,
                  gtkalpha($color, 0.4),
                  gtkalpha($color, 0.14) 7px,
                  gtkalpha($color, 0) 24px);
}

@mixin transition-shadows($color) {
  > dimming {
    background: none;
  }
  
  > border {
    background: none;
  }
  
  > shadow {
    min-width: 56px;
    min-height: 56px;
  
    &.left  { @include background-shadow(to right,  $color); }
    &.right { @include background-shadow(to left,   $color); }
    &.up    { @include background-shadow(to bottom, $color); }
    &.down  { @include background-shadow(to top,    $color); }
  }
}
